//
//  PhotoViewController.m
//  Scanner
//
//  Created by Misaya on 15/6/12.
//  Copyright (c) 2015年 米明. All rights reserved.
//

#import "PhotoViewController.h"
#import "UIImageView+WebCache.h"
@interface PhotoViewController ()
{
    UIImageView * _photoWall;
    UIActivityIndicatorView * _activity;
    void (^_remove)();
}
@end

@implementation PhotoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets=YES;
    self.edgesForExtendedLayout=UIRectEdgeNone;
    self.view.backgroundColor=[UIColor whiteColor];
    dispatch_async(dispatch_get_main_queue(), ^{
        
        _activity = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        
        [_activity startAnimating];
        
        self.navigationItem.titleView=_activity;
        self.title = @"加载中...";
        
        [self creatPhotoWall];

    });
        // Do any additional setup after loading the view.
}
-(void)creatPhotoWall{
    
    _photoWall = [[UIImageView alloc]init];
    
    if (self.photo) {
        
        _photoWall.image=self.photo;
        _photoWall.frame=CGRectMake(0, 0, ScreenSize.width, self.photo.size.height
                                    *ScreenSize.width/self.photo.size.width);
    }else if (self.photoUrl){
        
        NSString * url=self.photoUrl;
      
        [_photoWall sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            
            if (image.size.width>0) {
                _photoWall.frame=CGRectMake(0, 0, ScreenSize.width,image.size.height
                                            *ScreenSize.width/image.size.width);
                _photoWall.image=image;
            }
            
            [_activity stopAnimating];
            _activity = nil;
            self.title=nil;
        }];
        
        [self creatRightBtnItemWithTitle:@"删除"];
        
    }
    _photoWall.center=CGPointMake(ScreenSize.width/2.0, ScreenSize.height/2.0-Nav_Bar_Height);
   
    _photoWall.backgroundColor=[UIColor grayColor];
    
    [self.view addSubview:_photoWall];

}
-(void)rightBarBtnItem{
    _remove();
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)removePhoto:(void (^)())remove{
    _remove = nil;
    _remove = [remove copy];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
